package controller;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import model.PriorityDTO;
import model.UserDTO;
import util.UrlUtility;
import bizlogic.PriorityManager;
import bizlogic.UserManager;

@WebServlet("/DeleteUser")
public class DeleteUserServlet extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    public DeleteUserServlet() {
        super();
    }

	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doProcess(request, response);
	}

	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		doProcess(request, response);
	}
	
	private void doProcess(HttpServletRequest request,HttpServletResponse response) throws ServletException, IOException
	{
		UserManager um = new UserManager();
		UserDTO data;
		
		String id;
		boolean valid = true;
		String error = "";
		
		if ( request.getParameter("id") == null )  {
			valid = false;
			error = "user.error.useridrequired";
		} else {
			data = um.getUser(request.getParameter("id") );
			error = um.deleteUser(data);
			
			if ( !error.trim().equalsIgnoreCase("") ) valid = false;
		}
		
		UrlUtility.redirectPage(response, "LoadUser");
	}
	
}
